package com.hengtuo.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.text.TextPaint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hengtuo.kaiyuanzhongguo.R;
import com.hengtuo.vo.User;

import java.util.List;

/**
 * Created by msi on 2016/5/12.
 */
public class MoveballPraiseAdapter extends BaseAdapter {

    List<User> list;
    Context context;
    public static int i;

    public MoveballPraiseAdapter(List<User> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        convertView = LayoutInflater.from(context).inflate(R.layout.moveball_grid_item, null);

        TextView tv_moveball_grid_praise = (TextView) convertView.findViewById(R.id.tv_moveball_grid_praise);

        tv_moveball_grid_praise.setText(list.get(position).getName());
//        float TextWidth = getTextWidth(context, list.get(position).getName(), list.get(position).getName().length());
//
//        i = (int) TextWidth;

//        Paint paint = new Paint();
//
//        paint.setTextSize(tv_moveball_grid_praise.getTextSize());
//
//
//        float size =paint.measureText(tv_moveball_grid_praise.getText().toString());
//
//        i = (int) size;
//
        return convertView;
    }


    public float getTextWidth(Context context, String text, int textSize) {
        TextPaint paint = new TextPaint();
        float scaledDensity = context.getResources().getDisplayMetrics().scaledDensity;
        paint.setTextSize(scaledDensity * textSize);
        return paint.measureText(text);
    }
}
